from django.db import models

from apps.bookerInfo.models import User
from apps.flightInfo.models import RouteInfo

CLASS_CHOICES = (
    ('0', '头等舱'),
    ('1', '经济舱')
)
PAY_CHOICES = (
    ('0', '未支付'),
    ('1', '已支付'),
    ('2', '已取消')
)


class BookedTicket(models.Model):
    id = models.AutoField(verbose_name='机票id', db_column='id', primary_key=True)
    user_id = models.ForeignKey(User, models.DO_NOTHING, verbose_name='会员id')
    name = models.CharField(verbose_name='客户姓名', max_length=20)
    flight_id = models.ForeignKey(RouteInfo, models.DO_NOTHING, verbose_name='航线')
    from_place = models.CharField(verbose_name='出发城市', db_column='from_place', max_length=20)
    to_place = models.CharField(verbose_name='终点城市', db_column='to_place', max_length=20)
    ticket_date = models.DateTimeField(verbose_name='出发日期', db_column='ticket_date')
    class_type = models.CharField(verbose_name='舱位类型', db_column='class_type', choices=CLASS_CHOICES, max_length=1)
    seat_number = models.CharField(verbose_name='座位编号', db_column='seat_number', max_length=20, null=True)
    price = models.FloatField(verbose_name='机票价格', db_column='price')
    create_time = models.DateTimeField(verbose_name='预定时间', db_column='create_time', null=True)
    pay_status = models.CharField(verbose_name='状态', db_column='pay_status', max_length=1, choices=PAY_CHOICES,
                                  default=0)
    payment_amount = models.FloatField(verbose_name='支付金额', db_column='payment_amount', default=0)

    class Meta:
        db_table = 'booked_ticket'
        verbose_name_plural = '订票信息管理'
        # 作组合唯一约束，一个用户只能买一个航线的票
        unique_together = ('user_id', 'flight_id')
